package day14;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public
class Server {
    public static
    void main(String[] args) throws IOException {
        ServerSocket serverSocket =new ServerSocket(9999);
        while (true) {
            Socket client=serverSocket.accept();//阻塞式方法  等待客户端连接
            //通过线程模拟每个客户端，连接后的读写操作
            new ServerThread(client).start();
        }
    }
}
//只负责接受每个客户端的写入多次的数据
class ServerThread extends Thread {
    Socket client;
    public ServerThread(Socket client){
        this.client=client;
    }
    public void run() {
        try {
            BufferedReader br=new BufferedReader(new InputStreamReader(client.getInputStream()));
            while (true) {
                String msg=br.readLine();
                System.out.println(client.getInetAddress()+"："+msg);
            }
        } catch (Exception e) {

        }
    }
}